/*
 * LectorXML.java
 *
 * Created on September 29, 2007, 1:56 PM
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package wasolicitudesfiec.xml;

import java.io.IOException;
import java.io.InputStream;
import java.io.StringReader;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import org.w3c.dom.Document;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;

/**
 *
 * @author kabad
 */
public class LectorXML {
    
    /** Creates a new instance of LectorXML */
    public LectorXML() {
    }
    public Document leerXML(InputSource source ) throws SAXException, IOException, ParserConfigurationException{
        DocumentBuilderFactory builderFactory = DocumentBuilderFactory.newInstance();
        DocumentBuilder builder = null;
        
        builder = builderFactory.newDocumentBuilder();
        Document document = builder.parse(source);
        
        return document;
    }
       public Document leerXML(String source ) throws SAXException, IOException, ParserConfigurationException{
        DocumentBuilderFactory builderFactory = DocumentBuilderFactory.newInstance();
        DocumentBuilder builder = null;
        InputSource inputSource=new InputSource(new StringReader(source));
        builder = builderFactory.newDocumentBuilder();
        Document document = builder.parse(inputSource);
        
        return document;
    }
//    public Document leerXML(String source ) throws SAXException, IOException, ParserConfigurationException{
//        DocumentBuilderFactory builderFactory = DocumentBuilderFactory.newInstance();
//        DocumentBuilder builder = null;
//        
//        builder = builderFactory.newDocumentBuilder();
//        Document document = builder.parse(source);
//        
//        return document;
//    }
    public Document leerXML(InputStream source ) throws SAXException, IOException, ParserConfigurationException{
        DocumentBuilderFactory builderFactory = DocumentBuilderFactory.newInstance();
        DocumentBuilder builder = null;
        
        builder = builderFactory.newDocumentBuilder();
        Document document = builder.parse(source);
        
        return document;
    }
}
